/* EVENT JS */ 

/* When the page is load */ 
$(document).ready(function(){
	var curent_page = window.location.href.split('#');
	if(curent_page[1])
		displayContent(curent_page[1]);
	else
		displayContent("event");
});

function init_file(){
	jQuery(".file_supp .file").css("display", "none");
}

$(".old_version").live("click", function(e){
	e.preventDefault();
	jQuery(".file_supp .file").fadeIn('slow');
});

/* Height of ajax content */ 
function heightAjaxContent(){
	console.log(jQuery(document).height());
	$('.ajax_content').css('overflow-x', 'hidden');
	if(parseInt($('.ajax_content').css('height')) > jQuery(document).height()/2.2){
		$('.ajax_content').css('max-height', jQuery(document).height()/2.2);
		$('.ajax_content').css('overflow-y', 'auto');
	}else{
		$('.ajax_content').css('min-height', jQuery(document).height()/2.2);
	}
}

/* NavBar click */
$(document).ready(function(){
	$(".nav_event").find('li').live("click", function(e){
		e.preventDefault();
		if(!$(this).hasClass('active')){
			displayContent($(this).attr('id'));
		}
		return false;
	});
});

/* Display ajax content */
function displayContent(page){
	
	//var page = window.location.href+page;
	var divCible = $('.ajax_content');
	
	$('.ajax_content').css('overflow-y', 'auto');
	$('.nav_event').find('li').removeClass('active');
	$('#'+page).addClass('active');
	
	var DATA = "";
	$.ajax({
	   type: "GET",
	   url:page,
	   data: DATA,
	   
	   beforeSend: function(data){
			divCible.html('');
			divCible.addClass('ajax-loader');
	   },
	   success: function(sauv){
		   	divCible.removeClass('ajax-loader');
			divCible.html(sauv);
			heightAjaxContent();
			window.location.href = "#"+page;
			init_file();
	   }
	});
}

/* User Javascript Hover user detail */
jQuery(document).ready(function() {
	jQuery('.content_participant').css('height', jQuery('.participant').height()-60);
	
	jQuery('.participant').live('mouseleave', function(){}).live('mouseenter',  function(){
		jQuery('.content_participant').stop(false, true).fadeIn();
	});
	
	jQuery('#content_tab').live('mouseenter', function(){}).live('mouseleave',  function(){
		jQuery('.content_participant').stop(false, true).fadeOut();
	});
});

/* Comment textarea */ 
jQuery("#comment").live("click", function(){
	if($(this).val() == "Laisser un commentaire...")
		$(this).val("");
});

jQuery("#comment").live("blur", function(){
	if($(this).val() == "")
		$(this).val("Laisser un commentaire...");
});

jQuery("#comment").live("keyup", function(){
	if($(this).val() == "")
		$('.depose_comment').stop().fadeOut();
	else
		$('.depose_comment').stop().fadeIn();
});

/* Delete an event */ 
jQuery("#delete_event").live("click", function(){
	$('.ajax-modal').modal('toggle');
});